<?php
namespace app\admin\controller;


use app\admin\model\Alipay;
use app\admin\model\ProductSku;
use app\admin\model\UserDiscount;
use app\admin\model\UserScore;
use think\facade\View;


class Index extends Base
{
    public function index()
    {
//        dd($this->admin);
        return View::fetch('index');
    }

    public function excuteProductPrice()
    {
        die;
        $productSkuList = ProductSku::select();
//        dd($productSkuList);
        foreach ($productSkuList as $sku)
        {
//            dd($sku['price']);
            ProductSku::where('id', $sku['id'])->update([
                'price'=>round($sku['price'] * 1.1, 2),
                'origin_price'=>round($sku['origin_price'] * 1.1, 2),
                'cost_amount'=>round($sku['cost_amount'] * 1.1, 2),
            ]);
        }
    }

    public function excuteProduct()
    {
        die;
        $productList = \app\admin\model\Product::select();
        foreach ($productList as $item)
        {
            \app\admin\model\Product::where('id', $item['id'])->update([
                'describe'=>'发货时间2-7天',
            ]);
        }
    }

    public function excuteRecharge()
    {
        die;
        $list = UserScore::where('content', '管理员充值肉票(yichuang)')->select();
//        dd(count($list));
        foreach ($list as $item)
        {
            \app\admin\model\UserGoumaiMoney::create([
                'user_id'=>$item['user_id'],
                'amount'=>$item['score'],
                'type'=>'recharge',
                'content'=>'管理员【admin】充值',
                'before'=>$item['before'],
                'create_time'=>$item['create_time'],
            ]);
//            dd($item['user_id']);
        }
    }

    //批量处理用户折扣券记录
    public function excuteUserDiscount()
    {
        die;
        $list = \app\admin\model\User::select();
//        dd(count($list));
        foreach ($list as $item)
        {
            UserDiscount::create([
                'id'=>$item['id']
            ]);
        }
    }

    public function test(){
//        dd(1);
//        $arr = (new \app\admin\model\User())->getAllChildren(1);
//        dd($arr);

        (new Alipay())->test();
    }
}